package com.ats.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ats.model.Student;
import com.ats.model.User;
import com.ats.service.InstructorService_xh;
import com.ats.service.StudentService_xh;
import com.ats.service.TeacherService_xh;
import com.ats.service.UserSerivce_xh;
import com.ats.serviceimpl.InstructorServiceImpl_xh;
import com.ats.serviceimpl.StudentServiceImpl_xh;
import com.ats.serviceimpl.TeacherServiceImpl_xh;
import com.ats.serviceimpl.UserServiceImpl_xh;

import net.sf.json.JSONArray;
/**
 * 个人信息
 * @author xh
 *
 */
public class PerController_xh extends HttpServlet{
	UserSerivce_xh us = new UserServiceImpl_xh();
	StudentService_xh stus = new StudentServiceImpl_xh();
	InstructorService_xh ins = new InstructorServiceImpl_xh();
	TeacherService_xh  tea = new TeacherServiceImpl_xh();
		@Override
		protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
			// TODO Auto-generated method stub
		doPost(req, resp);
		}
		@Override
		protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
			resp.setCharacterEncoding("utf8");
			HttpSession session =req.getSession();
			PrintWriter  pw = resp.getWriter();
			int uid =Integer.parseInt(req.getParameter("uid"));
			//获取用户权限
			int ustate =us.getUstateByUid(uid);
			if(ustate==0){
				//辅导员信息回写页面
				JSONArray jsoins =ins.FindInstructorByUid(uid);
				pw.write(jsoins.toString());
			}else if(ustate==1){
				//老师信息回写页面
				JSONArray jsotea =tea.FindTeacherByUid(uid);
				pw.write(jsotea.toString());
			}else if(ustate==2){
				//学生信息回写页面
				JSONArray jsostu =stus.FindStudentByUid(uid);		
				pw.write(jsostu.toString());
			}
			pw.flush();
			pw.close();			
		}
}
